package com.chenxin.wms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.chenxin.common.annotation.WmsLogs;
import com.chenxin.wms.domain.vo.SupplierVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenxin.common.annotation.Log;
import com.chenxin.common.core.controller.BaseController;
import com.chenxin.common.core.domain.AjaxResult;
import com.chenxin.common.enums.BusinessType;
import com.chenxin.wms.domain.SupplierEntity;
import com.chenxin.wms.service.ISupplierService;
import com.chenxin.common.utils.poi.ExcelUtil;
import com.chenxin.common.core.page.TableDataInfo;

/**
 * 供应商资料Controller
 *
 * @author gry
 * @date 2025-04-10
 */
@RestController
@RequestMapping("/wms/supplier")
public class SupplierController extends BaseController {
    @Autowired
    private ISupplierService supplierService;

    /**
     * 查询供应商资料列表
     */
    @PreAuthorize("@ss.hasPermi('wms:supplier:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupplierEntity supplierEntity) {
        startPage();
        List<SupplierVO> list = supplierService.selectSupplierList(supplierEntity);
        return getDataTable(list);
    }

    /**
     * 导出供应商资料列表
     */
    @PreAuthorize("@ss.hasPermi('wms:supplier:export')")
    @Log(title = "供应商资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupplierEntity supplierEntity) {
        List<SupplierVO> list = supplierService.selectSupplierList(supplierEntity);
        ExcelUtil<SupplierVO> util = new ExcelUtil<>(SupplierVO.class);
        util.exportExcel(response, list, "供应商资料数据");
    }

    /**
     * 获取供应商资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:supplier:query')")
    @GetMapping(value = {"/", "/{supplierId}"})
    public AjaxResult getInfo(@PathVariable(value = "supplierId", required = false) Long supplierId) {
        return success(supplierService.selectSupplierBySupplierId(supplierId));
    }

    /**
     * 新增供应商资料
     */
    @PreAuthorize("@ss.hasPermi('wms:supplier:add')")
    @WmsLogs(name = "新增供应商")
    @PostMapping
    public AjaxResult add(@RequestBody SupplierEntity supplierEntity) {
        return toAjax(supplierService.insertSupplier(supplierEntity));
    }

    /**
     * 修改供应商资料
     */
    @PreAuthorize("@ss.hasPermi('wms:supplier:edit')")
    @Log(title = "供应商资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupplierEntity supplierEntity) {
        return toAjax(supplierService.updateSupplier(supplierEntity));
    }

    /**
     * 删除供应商资料
     */
    @PreAuthorize("@ss.hasPermi('wms:supplier:remove')")
    @Log(title = "供应商资料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{supplierIds}")
    public AjaxResult remove(@PathVariable Long[] supplierIds) {
        return toAjax(supplierService.deleteSupplierBySupplierIds(supplierIds));
    }
}
